package pe.com.chilis.delivery.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pe.com.chilis.delivery.log.UtilLog;
import pe.com.chilis.delivery.negocio.NParametros;

/**
 * Servlet implementation class SInspeccionVehicular
 */
public class SInspeccionVehicular extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SInspeccionVehicular() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		procesarRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		procesarRequest(request, response);
	}

	private void procesarRequest(HttpServletRequest request, HttpServletResponse response) {
		String accion = request.getParameter("accion");
		String pagina = "";
		try {
			if("0".equals(accion)){
				pagina = visualizarInspeccionVehicular(request, response);
			}else if("1".equals(accion)){
				pagina = grabarInspeccionVehicular(request, response);
			}
			
			response.sendRedirect(pagina);
			
		} catch (Exception e) {
			UtilLog.imprimirExcepcion(e);
		}
	}

	private String grabarInspeccionVehicular(HttpServletRequest request, HttpServletResponse response) {
		String pagina = "pages/registrarInspeccionVehicular.jsp";
		try {
			
			
			
		} catch (Exception e) {
			UtilLog.imprimirExcepcion(e);
		}
		return pagina;
	}

	private String visualizarInspeccionVehicular(HttpServletRequest request,
			HttpServletResponse response) {
		String pagina = "pages/registrarInspeccionVehicular.jsp";
		try {
			
			request.getSession().removeAttribute("objVehiculo");
			request.getSession().removeAttribute("lstVehiculo");
			
			request.getSession().setAttribute("lstMarcas", NParametros.buscarMarcasVehiculos());
			request.getSession().setAttribute("lstAnios", NParametros.buscarAnios());
			
		} catch (Exception e) {
			UtilLog.imprimirExcepcion(e);
		}
		return pagina;
	}

}
